﻿// -------------------------------------------------------------------------
//    @FileName         :    NFWorldData.cpp
//    @Author           :    gaoyi
//    @Date             :    2025-07-09
//    @Email			:    445267987@qq.com
//    @Module           :    NFWorldData
//
// -------------------------------------------------------------------------

#include "NFWorldData.h"

NFWorldData::NFWorldData()
{
    if (EN_OBJ_MODE_INIT == NFShmMgr::Instance()->GetCreateMode())
    {
        CreateInit();
    }
    else
    {
        ResumeInit();
    }
}

NFWorldData::~NFWorldData()
{
}

int NFWorldData::CreateInit()
{
    return 0;
}

int NFWorldData::ResumeInit()
{
    return 0;
}

int NFWorldData::LoadFromDB(const proto_ff::tbWorldData& dbData)
{
    m_stData.FromPb(dbData.m_stworlddata());
    return 0;
}

int NFWorldData::SaveToDB(proto_ff::tbWorldData& dbData)
{
    m_stData.ToPb(dbData.mutable_m_stworlddata());
    return 0;
}

int NFWorldData::InitConfig()
{
    if (m_stData.which_m_stData != 0)
    {
        CHECK_ERR(0, -1, "stWorldData.which_m_stData:{} has inited", m_stData.which_m_stData);
    }

    int iRetCode = InitDBData();
    CHECK_ERR(0, iRetCode, "InitDBData failed");

    if (m_stData.which_m_stData == 0)
    {
        CHECK_ERR(0, -1, "stWorldData.which_m_stData:{} not inited", m_stData.which_m_stData);
    }
    MarkDirty();
    return 0;
}

int NFWorldData::GetDbId()
{
    return NFGlobalSystem::Instance()->GetGlobalPluginManager()->GetZoneID() * 10000 + m_id;
}
